Skip to content
This repository was archived by the owner on Jan 23, 2026. It is now read-only.

MCP: relax the types for MCP parsing configs#365

Merged
jhaynie merged 1 commit intomainfrom
mcp-args
May 29, 2025
Merged

MCP: relax the types for MCP parsing configs#365
jhaynie merged 1 commit intomainfrom
mcp-args

Conversation

@jhaynie
Copy link
Copy Markdown
Member

@jhaynie jhaynie commented May 29, 2025

Summary by CodeRabbit

  • Refactor
    • Improved flexibility for command arguments and environment variables, allowing them to accept values of any type instead of only strings.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 29, 2025

Walkthrough

The changes update the types of command argument and environment variable fields and parameters from string-based collections to generic interface-based collections. This affects global variables, struct fields, and a method signature, allowing these elements to store values of any type rather than being restricted to strings. An unused helper function is also removed.

Changes

File(s) Change Summary
internal/mcp/config.go Changed types of argument and environment variable collections from string-based to interface-based; updated struct fields and method signatures accordingly; removed unused helper function toPathArray.

Poem

A hop and a skip, our types take a leap,
From strings to 'any', their bounds not so deep.
Arguments and envs, now flexible and free,
A garden of types, as wide as can be!
The old path array, now hops away—
More room for ideas, in code we play! 🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🔭 Outside diff range comments (1)
internal/mcp/config.go (1)

218-218: ⚠️ Potential issue

Potential runtime error due to type assumption in string concatenation.

This line assumes that elements in agentuityToolArgs and the result of append() will be strings, but with the new []any type, this could cause runtime panics if non-string types are present.

The code performs string concatenation but doesn't ensure type safety:

-if config.Config.AddIfNotExists(agentuityToolName, executable, append(agentuityToolArgs, "--"+config.Transport), agentuityToolEnv) {
+// Ensure type safety when building args
+args := make([]any, len(agentuityToolArgs)+1)
+copy(args, agentuityToolArgs)
+args[len(agentuityToolArgs)] = "--" + config.Transport
+if config.Config.AddIfNotExists(agentuityToolName, executable, args, agentuityToolEnv) {

Or add validation to ensure string types:

+// Validate that agentuityToolArgs contains only strings
+for i, arg := range agentuityToolArgs {
+    if _, ok := arg.(string); !ok {
+        return fmt.Errorf("agentuityToolArgs[%d] must be string, got %T", i, arg)
+    }
+}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ce91b98 and d1b900d.

📒 Files selected for processing (1)
  • internal/mcp/config.go (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Test CLI Upgrade Path (windows-latest)
  • GitHub Check: Build and Test (macos-latest)
  • GitHub Check: Analyze (go)
🔇 Additional comments (2)
internal/mcp/config.go (2)

55-55:

Details

✅ Verification successful

Verify method signature compatibility with existing callers.

The method signature change from string-specific types to any types is a breaking change that affects the public API.

Check for existing callers of this method to ensure compatibility:


🏁 Script executed:

#!/bin/bash
# Search for calls to AddIfNotExists method
rg -A 5 -B 2 "AddIfNotExists\(" --type go

# Search for any interface implementations that might be affected
ast-grep --pattern 'func ($_ *$_) AddIfNotExists($$$) $$$'

Length of output: 1725


No breaking changes detected for AddIfNotExists

A search for all callers of AddIfNotExists only returned its own invocation in internal/mcp/config.go. Since this lives in an internal package and isn’t used elsewhere, switching to []any/map[string]any poses no compatibility risks.


45-47:

Details

❓ Verification inconclusive

Assess the impact of relaxed typing on JSON serialization and external integrations.

The struct field type changes affect how MCP server configurations are handled:

  1. JSON Compatibility: Most MCP clients expect string values for args and env variables
  2. Validation: No validation ensures values are appropriate for command execution
  3. Type Coercion: Runtime type assertions may be needed when these values are used

Verify that existing MCP configurations remain compatible with this change:


🏁 Script executed:

#!/bin/bash
# Search for existing MCP configuration files and check their structure
fd -e json -x cat {} \; | jq '.mcpServers | .. | select(type == "object" and has("args")) | .args[]' 2>/dev/null || echo "No MCP configs found"

# Search for code that might expect string types from these fields
rg -A 3 -B 3 "\.Args\b|\.Env\b" --type go

Length of output: 12939


🏁 Script executed:

#!/bin/bash
# List MCP package files
echo "internal/mcp directory contents:"
ls -1 internal/mcp

# Display the config.go to inspect how Args and Env are loaded and used
echo -e "\n--- internal/mcp/config.go ---"
sed -n '1,200p' internal/mcp/config.go || true

# Display the util.go to see how the command is constructed and Env applied
echo -e "\n--- internal/mcp/util.go ---"
sed -n '1,200p' internal/mcp/util.go || true

Length of output: 6880


🏁 Script executed:

#!/bin/bash
# Inspect usage of MCPServerConfig.Args and Env within internal/mcp
echo "--- Search for Args and Env usage in internal/mcp ---"
rg -n "\.Args\b" -n internal/mcp
rg -n "\.Env\b" -n internal/mcp

# Display internal/mcp/mcp.go
echo -e "\n--- internal/mcp/mcp.go (first 200 lines) ---"
sed -n '1,200p' internal/mcp/mcp.go || true

# Display internal/mcp/deploy.go
echo -e "\n--- internal/mcp/deploy.go (first 200 lines) ---"
sed -n '1,200p' internal/mcp/deploy.go || true

Length of output: 3048


🏁 Script executed:

#!/bin/bash
# Locate CLI command files related to MCP
echo "--- Matching files under cmd/ containing 'mcp' ---"
fd -g "cmd/*mcp*.go" || echo "None found"

# Search for mcpClientConfigs usage
echo -e "\n--- Search for mcpClientConfigs ---"
rg -n "mcpClientConfigs" -n .

# Inspect cmd entrypoint(s) for MCP commands
echo -e "\n--- Inspect cmd/mcp.go or similar ---"
if [ -f cmd/mcp.go ]; then
  sed -n '1,200p' cmd/mcp.go
else
  for f in $(fd -g "*mcp*.go" cmd); do
    echo "--- $f ---"
    sed -n '1,200p' "$f"
  done
fi

# Examine internal/util/api.go for use of MCPServerConfig fields
echo -e "\n--- internal/util/api.go (first 200 lines) ---"
sed -n '1,200p' internal/util/api.go || true

Length of output: 12048


MCPServerConfig JSON typing – please validate external client compatibility

The change in internal/mcp/config.go from []string/map[string]string to []any/map[string]any only affects JSON serialization of the MCP config file (no internal code paths consume these values at runtime). However, external MCP client implementations (Cursor, Windsurf, etc.) almost certainly expect:

  • args as an array of strings
  • env as a map of string→string

Please verify that any downstream consumers of your ~/.agentuity/mcp/config.json will tolerate non-string JSON values or else:

• Constrain the types back to []string/map[string]string.
• Or add validation in loadConfig/AddIfNotExists to enforce string values and reject or coerce invalid types.

Locations to review:

  • internal/mcp/config.go (struct definition at lines ~45–47)
  • Save()/loadConfig() JSON round-trip behavior

Comment thread internal/mcp/config.go
Comment on lines +24 to +25
var agentuityToolArgs = []any{"mcp", "run"}
var agentuityToolEnv = map[string]any{}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider the implications of relaxing type safety for global configuration variables.

While changing from []string to []any and map[string]string to map[string]any provides more flexibility for MCP configurations, it introduces potential runtime risks:

  1. Type Safety Loss: Compile-time type checking is reduced, potentially leading to runtime errors
  2. String Operations: Line 218 uses string concatenation ("--"+config.Transport) which assumes string types
  3. JSON Unmarshaling: When unmarshaling JSON into []any, numeric values might become float64 instead of expected types

Consider adding type validation or using a more structured approach:

-var agentuityToolArgs = []any{"mcp", "run"}
-var agentuityToolEnv = map[string]any{}
+var agentuityToolArgs = []any{"mcp", "run"}
+var agentuityToolEnv = map[string]any{}

+// Helper function to ensure string conversion
+func toStringSlice(args []any) []string {
+    result := make([]string, len(args))
+    for i, arg := range args {
+        result[i] = fmt.Sprintf("%v", arg)
+    }
+    return result
+}

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In internal/mcp/config.go around lines 24 to 25, the change from []string to
[]any and map[string]string to map[string]any reduces type safety and risks
runtime errors, especially where string operations like concatenation assume
string types. To fix this, revert these variables to their original typed forms
or implement strict type validation and conversion before usage. Additionally,
ensure JSON unmarshaling handles type assertions properly to avoid float64
misinterpretation by defining structured types or adding explicit type checks.

@jhaynie jhaynie merged commit edb8739 into main May 29, 2025
14 checks passed
@jhaynie jhaynie deleted the mcp-args branch May 29, 2025 19:55
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant